package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.MsgAwardActivity;
import com.sxm.yiwei.beans.Award;
import com.sxm.yiwei.tools.CastTime;
import com.sxm.yiwei.tools.CircleTransform;
import com.sxm.yiwei.utils.InternetAddressUtis;

import org.xutils.x;

import java.util.List;

/**
 * Created by KuKa on 2017/7/28.
 * 打赏列表
 */

public class AwardAdapter extends BaseAdapter {

    Context context;
    List<Award.DataBean> list;
    public AwardAdapter(Context context, List<Award.DataBean> list) {
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder holder;
        if (convertView==null){
            view = View.inflate(context, R.layout.award_item,null);
            holder = new ViewHolder();
            holder.img = (ImageView) view.findViewById(R.id.award_img);
            holder.name = (TextView) view.findViewById(R.id.award_name);
            holder.time = (TextView) view.findViewById(R.id.award_time);
            holder.money = (TextView) view.findViewById(R.id.award_money);

            view.setTag(holder);
        }else {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        }
        holder.name.setText(list.get(position).getNickname());
        holder.money.setText(list.get(position).getAmount()+"");
        holder.time.setText(CastTime.CastTime(list.get(position).getTime()));

        Picasso.with(context).load(InternetAddressUtis.IMG_URL+ list.get(position).getAvatar()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(holder.img);

        notifyDataSetChanged();
        return view;
    }

    class ViewHolder{
        ImageView img;
        TextView name,time,money,delete;
    }
}
